package com.example.food_contract_system.controller;

import com.example.food_contract_system.service.ShoppingCartService;
import com.example.food_contract_system.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiHaoyang
 * @date 2023/7/11  10:43
 **/
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 购物车手动保存
     * @param productList
     * @param aId
     * @return
     */
    @PostMapping("/saveShoppingCart/{aId}")
    public R saveShoppingCart(@RequestBody String productList,
                               @PathVariable("aId") String aId){
        R result = shoppingCartService.saveShoppingCart(productList,aId);
        return result;
    }

    /**
     * 获取购物车信息
     * @return
     */
    @GetMapping("/getShopping/{aid}")
    public R getShopping(@PathVariable("aid")String aId){
        R result = shoppingCartService.getShopping(aId);
        return result;
    }

    /**
     * 删除 指定的购物车信息
     * @param sId
     * @return
     */
    @GetMapping("/deleteCart/{sId}")
    public R deleteCart(@PathVariable("sId") String sId){
        R result = shoppingCartService.deleteCart(sId);

        return result;
    }
}
